
<script type="text/javascript">
  var cover = $('#{$showid}').attr('src');
  console.log($('#{$showid}').attr('src'));
  $('#{$showid}').editable({
    type: 'image', value: null,
    image: {
      thumbnail: 'large',
      btn_choose: '{$btnchoose}',
      droppable: true,
      name: 'avatarfile-{$callbackid}',
      max_size: 1100000,
      on_error : function(code) {
        if(code == 1) {
          return alert('请上传jpg|gif|png图片', '文件错误');
        } else if(code == 2) {
          return alert('图片大小不能超过11M', '文件太大');
        }
        else {
          return alert('错误代码：' + code, '未知错误');
        }
      }
    },
    url: function(params) {
      var deferred = new $.Deferred,
        thumb = $('input[name="avatarfile-{$callbackid}"]')[0].files[0];
      if (!thumb) {
        deferred.reject('获取图片失败！！');
      } else {
        var avatarfile = document.querySelector('input[name=avatarfile]');
        var formData = new FormData();
        formData.append('image', thumb);
        formData.append('type', '{$type}');
        $.ajax({
          type: 'POST', dataType: 'json',
          data: formData, processData: false,
          contentType: false,
          url: '{url("admin/file/image")}',
        }).done(function(res) {
          if (res.code) {
            deferred.reject(res.msg);
          } else {
            deferred.resolve(res.result);
          }
        }).fail(function() {
          deferred.reject('{$btnchoose}失败，请重新上传！！');
        })
      }
      return deferred.promise();
    },
    success: function(response, newValue) {
      $('#{$callbackid}').val(response.url);
      $('#{$callbackid}').change();
      alert('{$btnchoose}成功！!');
    },
    error: function(message, newValu) {
      alert(message, '{$btnchoose}失败!!');
    }
  });

  $('#{$callbackid}').change(function() {
    $('#{$showid}').attr('src', this.value || cover);
  });
  </script>